﻿//推广部需求：投放右侧客服窗口
//第一次10秒出现 被关闭后 第二次再隔30秒 连续两次关闭 不出现
InitPkt();
var ShowCustomerServiceCount = 0;   //统计关闭次数
function InitPkt() {

    var showPktHost = window.location.href;
    var html = "", html2 = '';

    //加入客服系统
    //html += '<script language="javascript" src="http://pkt.zoosnet.net/JS/LsJS.aspx?siteid=PKT75241920&float=1&lng=cn"></script>';
    document.write('<script language="javascript" src="http://pkt.zoosnet.net/JS/LsJS.aspx?siteid=PKT75241920&float=1&lng=cn"></script>');

    //加入左侧排版
    html += "\r\n";

    html += "<style>\r\n";
    html += "\r\n";
    html += "\r\n";
    html += ".fl_fix {\r\n";
    html += "    position:fixed;\r\n";
    html += "    left:0px;\r\n";
    html += "    top:20%;\r\n";
    html += "    width:136px;\r\n";
    html += "    height:200px;\r\n";
    html += "    background:url(http://static.yingsheng.com/sso.yingsheng.com/content/images/kefu_2.png) no-repeat top;\r\n";
    html += "    padding-top:230px;\r\n";
    html += "    z-index:9999;\r\n";
    html += "}\r\n";
    html += "\r\n";
    html += "    .fl_fix .close {\r\n";
    html += "        width: 24px;\r\n";
    html += "        height: 24px;\r\n";
    html += "        position: absolute;\r\n";
    html += "        right: 0;\r\n";
    html += "        top:0;\r\n";
    html += "        display: block;\r\n";
    html += "    }\r\n";
    html += "    .fl_fix .web_qq,.fl_fix .swt {\r\n";
    html += "        display:block;\r\n";
    html += "        height:35px;\r\n";
    html += "    }\r\n";
    html += "\r\n";
    html += "    .fl_fix .hd_link {\r\n";
    html += "        display:block;\r\n";
    html += "        height:120px;\r\n";
    html += "        margin-top:10px;\r\n";
    html += "    }\r\n";


    html += ".fr_fix {\r\n";
    html += "    position: fixed;\r\n";
    html += "    right: 0px;\r\n";
    html += "    bottom: 0px;\r\n";
    html += "    width: 340px;\r\n";
    html += "    z-index: 999;\r\n";
    html += "}\r\n";
    html += "    .fr_fix .close {\r\n";
    html += "        width: 20px;\r\n";
    html += "        height: 20px;\r\n";
    html += "        position: absolute;\r\n";
    html += "        right: 0;\r\n";
    html += "        top: 0;\r\n";
    html += "        display: block;\r\n";
    html += "    }\r\n";
    html += '.layer_kefu{position:fixed;top:50%;left:50%;z-index:999999;margin-top:-167px;margin-left:-266px;padding-top:175px;padding-left:85px;width:28pc;height:158px;background:url(http://static.yingsheng.com/www.yingsheng.com/content/images/global/kefu_bg2.png) no-repeat;color:#fff;text-align:center;font-size:20px;line-height:28px}.layer_kefu_close{position:absolute;top:10px;right:10px;font-size:0}.layer_kefu_close a{position:absolute;top:-28px;right:-28px;margin-left:0;width:30px;height:30px;background:url(http://www.yingsheng.com/js/libs/layer/v1.8.5/skin/default/xubox_ico0.png) no-repeat;background-position:-60px -195px}.kefu_btn{margin-top:20px}.kefu_btn .q_after,.kefu_btn .q_now{display:inline-block;margin-right:25px;width:130px;height:30px;border-radius:20px;background:#d74309;color:#fff;font-size:1pc;line-height:30px;cursor:pointer}.layer_kefu .q_after{background:#efac2f}\r\n';

    //*邀请对话窗口*//
    html += '.yqdh{margin-bottom:50%;height:141px;width:290px;display:block;top:50%;left:50%;margin:-80px 0 0 -145px;position:fixed;}.yqdh .close{background:url(images/yqdh/m/close.png) center no-repeat;width:24px;height:24px;float:right;cursor:pointer}.yqdh .close-btn{background:url(images/yqdh/m/close-next.png) center no-repeat;width:85px;height:22px;float:left;cursor:pointer;margin-top:100px;margin-left:5px}.yqdh .talk{background:url(images/yqdh/m/talk.png) center no-repeat;width:85px;height:22px;float:left;cursor:pointer;margin-top:100px;margin-left:90px}';
    html += "</style>\r\n";
    html += "\r\n";

    //alert(showPktHost.indexOf("/course-") == -1);
    if (showPktHost.indexOf("/course-") == -1) {
        //非课程类-居中
        //alert('非课程类-居中');
    }
    else {
        //课程类-居右
        //alert('课程类-居右');
    }

    //id:CustomerServiceLeft 左侧客服
    html += "\r\n";
    html += "    <div class='fl_fix' id='CustomerServiceLeft'>\r\n";
    html += "        <a class='close' href='javascript:;' onclick='ShowCustomerServiceRight(true)'></a>\r\n";
    html += "        <a  class='web_qq' title='免费注册' href='javascript:void(0)' onclick='OpenLoginOrRegBox(\"wz\",\"0\")'></a>\r\n";
    html += "        <a onclick='ysCounterUrlTalkData();openZoosUrl();return false;' href='javascript:void(0)' class='swt'></a>\r\n";
    html += "        <a  target='_blank' href='http://www.yingsheng.com/project/activity/SpecialRegGuide.aspx' class='hd_link'></a>\r\n";
    html += "    </div>\r\n";
    html += "\r\n";

    try {
        showKF2 = showKF2 ? true : false;
    } catch (e) {
        showKF2 = false;
    }

    if (showKF2) {
        html += '<div class="layer_kefu" id="CustomerServiceRight">\r\n';
        html += '<div class="layer_kefu_close">\r\n';
        html += '    <a href="javascript:;" onclick="ShowCustomerServiceLeft(true)"></a>\r\n';
        html += '</div>\r\n';
        html += '    <p>HI,欢迎光临英盛网</p>\r\n';
        html += '    <p>聊聊看,小英会迅速帮您解答</p>\r\n';
        html += '    <p>客服热线：4006664343</p>\r\n';
        html += '    <div class="kefu_btn">\r\n';
        html += '        <a href="javascript:;" class="q_now"onclick="ysCounterUrlTalkData();openZoosUrl();return false;" target="_blank" title="马上交谈">马上交谈</a>\r\n';
        html += '        <a class="q_after" title="在线注册" href="javascript:void(0)" onclick="OpenLoginOrRegBox(\'wz\',\'0\')">在线注册</a>\r\n';
        html += '   </div>\r\n';
        html += '</div>\r\n';
    } else {
        html += "    <div class='fr_fix' id='CustomerServiceRight' style='display:none'>\r\n";
        html += "        <a class='close' href='javascript:;' onclick='ShowCustomerServiceLeft(true)'></a>\r\n";
        html += "        <a href='javascript:;' onclick='ysCounterUrlTalkData();openZoosUrl();return false;'>\r\n";
        html += "            <img style='width:100%;' src='http://www.yingsheng.com/content/images/global/kf.gif' border=0 />\r\n";
        html += "        </a>\r\n";
        html += "    </div>\r\n";
        html += "\r\n";
    }

    //*邀请对话窗口*//
    html += '<div class="yqdh" style="display:none;"><div class="close" onclick="LR_Hide();LR_RefuseChat();return false;" ></div><div class="talk" onclick="openZoosUrl();LR_Hide();return false;"></div><div class="close-btn" onclick="LR_Hide();LR_RefuseChat();return false;" ></div></div>';
    //html += '<div class="yqdh" style="display:none;"><img src="http://static.yingsheng.com/www.yingsheng.com/content/images/global/yqdh.jpg" usemap="yqdh"></div><map name="yqdh" id="yqdh"><area shape="circle" coords="380,10,50" nohref="nohref" onclick="LR_Hide();LR_RefuseChat();return false;" /><area shape="rect" coords="130,120,250,160" nohref="nohref" onclick="openZoosUrl();LR_Hide();return false;" /><area shape="rect" coords="2550,120,250,160" nohref="nohref"onclick="LR_Hide();LR_RefuseChat();return false;" /></map>';
    document.write(html);

    //var ShowCustomerServiceRight = setTimeout('ShowCustomerServiceRight(false)', 20 * 1000);//20秒后显示右侧客服

}

/**
计数器
*/
function ysCounterUrlTalkData() {
    //写入计数器
    var $ysCounterUrlTalkData = {};
    $ysCounterUrlTalkData.url = location.href;
    $ysCounterUrlTalkData.referurl = document.referrer;
    $ysCounterUrlTalkData.event = 'talk';
    $.ajax({
        type: "get",
        async: true,	//false时执行完再继续执行
        url: 'http://global.yingsheng.com/counter/ysCounterAjax/Add',
        data: $ysCounterUrlTalkData,
        callback: "callback",
        dataType: "jsonp",
        success: function (dataSet) {
            console.log(dataSet);
            //console.log("ysCounter success!");
        }, error: function (e) {
            console.log("ysCounter network error!" + e);
        }
    });
}

//显示左侧客服
function ShowCustomerServiceLeft(addCount) {
    if (addCount == true) {
        ShowCustomerServiceCount++;
    }
    clearTimeout(ShowCustomerServiceRight);
    ShowCustomerServiceRightPosition();
    if (ShowCustomerServiceCount > 1) {
        CloseCustomerService(); //全关闭
    } else {
        $("#CustomerServiceLeft").show();
        $("#CustomerServiceRight").hide();
    }
}

//显示右侧客服
function ShowCustomerServiceRight(addCount) {
    //全部关闭
    CloseCustomerService();
    return;
    if (addCount == true) {
        ShowCustomerServiceCount++;
    }
    clearTimeout(ShowCustomerServiceRight);
    ShowCustomerServiceRightPosition();
    if (ShowCustomerServiceCount > 1) {
        CloseCustomerService(); //全关闭
    } else {
        $("#CustomerServiceLeft").hide();
        $("#CustomerServiceRight").show();
    }
}

//对右侧客服的位置进行修正
function ShowCustomerServiceRightPosition() {
    if ($.cookie('isShowGlobal_ad_bottom_div') == null || $.cookie('isShowGlobal_ad_bottom_div') == undefined) {
        var showPktHost = window.location.host;
        if (showPktHost != "www.yingsheng.com") {
            $("#global_ad_bottom_div").hide();
            $(".fr_fix").css("bottom", "0");
            $("body").css("padding-bottom", "0");
        }
        $(".fr_fix").css("bottom", "0");
    } else {
        $("#global_ad_bottom_div").hide();
        $(".fr_fix").css("bottom", "0");
        $("body").css("padding-bottom", "0");
    }
}

//客服全关闭
function CloseCustomerService() {
    clearTimeout(ShowCustomerServiceRight);
    $("#CustomerServiceLeft").hide();
    $("#CustomerServiceRight").hide();
}

// var timer = setInterval(isShow, 200);

function isShow() {
    try {
        if ($('#LRdiv1').is(":visible")) {

            /*            console.log('show');
             */
            /*            clearInterval(timer);*/
            $('#LRdiv1').hide();

            $(".yqdh").show();

        } else {
            /*          console.log('hide');
             */
        }
    }catch (e){}
}

function LR_Hide() {
    $(".yqdh").hide();
}